#include "LPC11XX.H"
#include "LED.h"

void LEDInit()
{
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); 
    LPC_IOCON->PIO2_0 &= ~0x07;    
    LPC_IOCON->PIO2_0 |= 0x01; 
    LPC_IOCON->PIO2_1 &= ~0x07;   
    LPC_IOCON->PIO2_1 |= 0x01; 
    LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<16); 
    
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);     
    LPC_GPIO2->DIR |= (1<<0); 
    LPC_GPIO2->DATA |= (1<<0); 
    LPC_GPIO2->DIR |= (1<<1); 
    LPC_GPIO2->DATA |= (1<<1); 
}


void PIOINT1_IRQHandler()
{
    if((LPC_GPIO3->MIS & (1<<0))==(1<<0)) 
    {
        LED1_ON();
        while(KEY1_DOWN());
        LED1_OFF();
        LPC_GPIO3->IC = (1<<0); 
    }
    if((LPC_GPIO3->MIS & (1<<1))==(1<<1)) 
    {
        LED2_ON();
        while(KEY2_DOWN());
        LED2_OFF();
        LPC_GPIO3->IC = (1<<1); 
    }
}

